<template>
  <div class="h5-tabs">
    <div class="tabs-wrapper">
      <div 
        v-for="(tab, index) in tabs" 
        :key="index"
        class="tab-item"
        :class="{ active: activeIndex === index }"
        @click="handleTabClick(index)"
      >
        {{ tab.label }}
      </div>
      <div 
        class="indicator" 
        :style="{ 
          left: `${100 * activeIndex / tabs.length}%`,
          width: `${100 / tabs.length}%`
        }"
      >
        <div class="indicator-inner"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'H5Tabs',
  props: {
    tabs: {
      type: Array,
      required: true,
      default: () => []
    },
    modelValue: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      activeIndex: this.modelValue
    }
  },
  watch: {
    modelValue(newVal) {
      this.activeIndex = newVal
    }
  },
  methods: {
    handleTabClick(index) {
      this.activeIndex = index
      this.$emit('update:modelValue', index)
      this.$emit('change', index)
    }
  }
}
</script>

<style lang="scss" scoped>
.h5-tabs {
  width: 100%;
  .tabs-wrapper {
    position: relative;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-bottom: 1px solid #eee;
    
    .tab-item {
      flex: 1;
      padding: 12px 0;
      text-align: center;
      font-size: 14px;
      color: #666;
      cursor: pointer;
      transition: color 0.3s;
      
      &.active {
        color: #6366f1;
        font-weight: 500;
      }
    }
    
    .indicator {
      position: absolute;
      bottom: -1px;
      height: 3px;
      transition: all 0.3s;
      display: flex;
      justify-content: center;
      
      .indicator-inner {
        width: 20px;
        height: 100%;
        background-color: #6366f1;
        border-radius: 3px;
      }
    }
  }
}
</style>
